//
//  ScanVC.swift
//  StoreProject
//
//  Created by CYC on 1998/3/3.
//

import UIKit
import swiftScan

class ScanVC: LBXScanViewController, LBXScanViewControllerDelegate {
    
    typealias ScanVCBlock = (_ text: String) -> Void
    var textBlock: ScanVCBlock?

    override func viewDidLoad() {
        super.viewDidLoad()

        //设置扫码区域参数
        var style = LBXScanViewStyle()
        
        style.centerUpOffset = 60;
        style.xScanRetangleOffset = 30;
        
        if UIScreen.main.bounds.size.height <= 480
        {
            //3.5inch 显示的扫码缩小
            style.centerUpOffset = 40;
            style.xScanRetangleOffset = 20;
        }
        
        
        style.color_NotRecoginitonArea = UIColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 0.4)
        
        
        style.photoframeAngleStyle = LBXScanViewPhotoframeAngleStyle.Inner;
        style.photoframeLineW = 2.0;
        style.photoframeAngleW = 16;
        style.photoframeAngleH = 16;
        
        style.isNeedShowRetangle = false;
        
        style.anmiationStyle = LBXScanViewAnimationStyle.NetGrid;
        style.animationImage = UIImage(named: "CodeScan.bundle/qrcode_scan_full_net")
        
        self.scanStyle = style
        self.scanResultDelegate = self
        
        
        
    }
    
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        
        let btn = UIButton.init(frame: CGRect.init(x: 0, y: kScreenHeight - 80 - kSpaceSize, width: kScreenWidth, height: 80))
        btn.c_setImage("231")
        btn.backgroundColor = .clear
        btn.addTarget(self, action: #selector(button1Action(btn:)), for: .touchUpInside)
        self.view.addSubview(btn)
    }
    
    // MARK:打开相册
    @objc func button1Action(btn: UIButton) {
        
        self.openPhotoAlbum()
        
    }
    
    // MARK:扫一扫结果
    func scanFinished(scanResult: LBXScanResult, error: String?) {
        
        if scanResult.strScanned != nil {
            
            self.textBlock!(scanResult.strScanned!)
        }
    }
}
